﻿using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;

namespace SimpleMVC
{
    public class BundleConfig
    {
        // 有关绑定的详细信息，请访问 http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // 使用要用于开发和学习的 Modernizr 的开发版本。然后，当你做好
            // 生产准备时，请使用 http://modernizr.com 上的生成工具来仅选择所需的测试。
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            RegisterThemeBundles(bundles,
                "Default",
                new string[] {"~/Content/Default/bootstrap.min.css", "~/Content/Default/Site.css"},
                null);

            RegisterThemeBundles(bundles,
                "Cerulean",
                new string[] { "~/Content/Cerulean/bootstrap.min.css", "~/Content/Cerulean/Site.css" },
                null);
        }
        
       

        public static Dictionary<string, ThemeBundles> AllThemeBundles = new Dictionary<string, ThemeBundles>();


        static void RegisterThemeBundles(BundleCollection bundles,string theme, string[] styleFiles, string[] scriptFiles)
        {
            ThemeBundles themeBundles = null;
            if (AllThemeBundles.ContainsKey(theme))
            {
                themeBundles = AllThemeBundles[theme];
            }
            else
            {
                themeBundles = new ThemeBundles();
            }
            if (styleFiles != null && styleFiles.Length > 0)
            {
                string themeCss = string.Format("~/Content/{0}/css", theme);
                bundles.Add((new StyleBundle(themeCss).Include(styleFiles)));
                themeBundles.ThemeCsses.Add(themeCss);
            }
            if (scriptFiles != null && scriptFiles.Length > 0)
            {
                string themeScipt = string.Format("~/bundles/{0}", theme);
                bundles.Add((new ScriptBundle(themeScipt).Include(scriptFiles)));
                themeBundles.ThemeScipts.Add(themeScipt);
            }
            AllThemeBundles[theme] = themeBundles;
        }
    }
    public class ThemeBundles
    {
        public ThemeBundles()
        {
            ThemeCsses = new HashSet<string>(); ;
            ThemeScipts = new HashSet<string>();
        }
        public ICollection<string> ThemeCsses { set; get; }

        public ICollection<string> ThemeScipts { set; get; }
    }
}
